import { CHANNELS_ACTIVE, CHANNELS_GET } from '../constants'

export default function channels(
  state = {
    lists: [],
    active: '',
  },
  action
) {
  switch (action.type) {
    case CHANNELS_GET:
      // dispatch({type: CHANNELS_GET, payload: 后端返回的数据})
      return {
        ...state,
        lists: action.payload,
        active: action.payload[0].id, // 默认是第0个对象的 id
      }
    case CHANNELS_ACTIVE:
      return {
        ...state,
        active: action.id,
      }
    default:
      return state
  }
}
